package org.zhao.nettydemos.echoServer;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: xiaohui.zhao
 * @Date: 2021/9/15 16:39
 * @Description:
 */
@Slf4j
public class NettyEchoClientHandler extends ChannelInboundHandlerAdapter {

    public static final NettyEchoClientHandler INSTANCE = new NettyEchoClientHandler();

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;
        int len = byteBuf.readableBytes();
        byte[] arr = new byte[len];
        byteBuf.getBytes(0,arr);
        log.info("client received : "+ new String(arr,"UTF-8"));

        //释放bytebuf
        byteBuf.release();
        //super.channelRead(ctx, msg);
    }
}